<template>
  <div class="scaleDialog">
    <basic-container>
      <avue-crud
        :option="option"
        :data="data"
        v-model="item"
        @on-load="onLoad"
        @search-change="searchGridInfo"
        @selection-change="selectionChange"
        :search.sync="search"
        @refresh-change="onLoad"
      >
        <!-- <template slot-scope="{ type, size, row }" slot="menu">
          <el-button
            icon="el-icon-check"
            :size="size"
            :type="type"
            @click="handlePreview(row)"
            >预览
          </el-button>
        </template> -->
        <template slot="menuLeft">
          <el-button
            type="primary"
            size="small"
            icon="el-icon-plus"
            @click="submitInfo"
            >添加绑定量表</el-button
          >
          <el-button size="small" icon="" @click="cancelDialog">取消</el-button>
        </template>
      </avue-crud>
    </basic-container>
    <!-- <QuestionPreview
      :gaugeId="gaugeId"
      :visible.sync="questionPreviewVisible"
    ></QuestionPreview> -->
  </div>
</template>

<script>
import { saveProjectgaugerelation, getList2 } from "@/api/census/scale";
// import QuestionPreview from "./settings/question-preview.vue";
export default {
  name: "scaleDialog",
  props: ["gaugeIdList"],
  data() {
    return {
      item: {},
      questionPreviewVisible: false,
      search: {},
      gaugeId: "",
      selectionList: [],
      promote: true,
      page: {
        pageSize: 20,
      },
      option: {
        addBtnText: "添加量表",
        addBtn: false,
        excelBtn: false,
        selectClearBtn: false,
        delBtn: false,
        border: true,
        index: true,
        selection: true,
        editBtn: false,
        columnBtn: false,
        searchShowBtn: false,
        expandLevel: 3,
        headerAlign: "left",
        align: "left",
        tree: false,
        maxHeight: 200,
        labelWidth: 100,
        menuWidth: 100,
        menu: false,
        column: [
          {
            width: 200,
            label: "编码",
            overHidden: true,
            prop: "gaugeNo",
          },
          {
            label: "量表类别",
            prop: "gaugeTypeId",
            type: "select",
            searchSpan: 10,
            search: true,
            props: {
              label: "typeName",
              value: "gaugeTypeId",
            },
            dicUrl: `/api/blade-measure/measure/gaugetype/listAll`,
          },
          {
            label: "量表名",
            prop: "title",
            searchSpan: 10,
            search: true,
          },
        ],
      },
      data: [],
      query: {},
      userInfo: {},
    };
  },
  created() {
    let info = JSON.parse(localStorage.getItem("saber-userInfo")).content;
    this.userInfo = info;
  },
  methods: {
    async onLoad(page = this.page, params = {}) {
      if (this.userInfo.account !== "admin") params.status = 1;
      const {
        data: { data },
      } = await getList2(1, 1000, Object.assign(params, this.query));
      this.data = data.records.filter(
        (item) => this.gaugeIdList.indexOf(item.gaugeId) == -1
      );
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    submitInfo() {
      this.selectionList.map((item) => {
        item.projectId = this.$route.query.projectId;
      });
      let params = {
        projectGaugeRelationEntityList: this.selectionList,
      };
      saveProjectgaugerelation(params).then(() => {
        this.$emit("onloadInfo");
        this.$emit("close");
        this.$message({
          type: "success",
          message: "操作成功!",
        });
      });
    },
    cancelDialog() {
      this.$emit("close");
    },
    async searchGridInfo(params, done) {
      await this.onLoad(this.page, params);
      done();
    },
    handlePreview(row) {
      this.gaugeId = row.gaugeId;
      this.questionPreviewVisible = true;
    },
  },
};
</script>

<style lang="scss" scoped>
.scaleDialog {
}
</style>
